package com.ruoyi.system.service.impl;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.support.Convert;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.HatchetOrderPayment;
import com.ruoyi.system.mapper.HatchetOrderPaymentMapper;
import com.ruoyi.system.service.IHatchetOrderPaymentService;

/**
 * 订单 服务层实现
 * 
 * @author ruoyi
 * @date 2019-02-20
 */
@Service
public class HatchetOrderPaymentServiceImpl implements IHatchetOrderPaymentService {
	@Autowired
	private HatchetOrderPaymentMapper hatchetOrderPaymentMapper;

	/**
	 * 查询订单信息
	 * 
	 * @param iD
	 *            订单ID
	 * @return 订单信息
	 */
	@Override
	public HatchetOrderPayment selectHatchetOrderPaymentById(String iD) {
		return hatchetOrderPaymentMapper.selectHatchetOrderPaymentById(iD);
	}

	/**
	 * 查询订单列表
	 * 
	 * @param hatchetOrderPayment
	 *            订单信息
	 * @return 订单集合
	 */
	@Override
	public List<HatchetOrderPayment> selectHatchetOrderPaymentList(HatchetOrderPayment hatchetOrderPayment) {
		return hatchetOrderPaymentMapper.selectHatchetOrderPaymentList(hatchetOrderPayment);
	}

	/**
	 * 新增订单
	 * 
	 * @param hatchetOrderPayment
	 *            订单信息
	 * @return 结果
	 */
	@Override
	public int insertHatchetOrderPayment(HatchetOrderPayment hatchetOrderPayment) {
		return hatchetOrderPaymentMapper.insertHatchetOrderPayment(hatchetOrderPayment);
	}

	/**
	 * 修改订单
	 * 
	 * @param hatchetOrderPayment
	 *            订单信息
	 * @return 结果
	 */
	@Override
	public int updateHatchetOrderPayment(HatchetOrderPayment hatchetOrderPayment) {
		return hatchetOrderPaymentMapper.updateHatchetOrderPayment(hatchetOrderPayment);
	}

	/**
	 * 删除订单对象
	 * 
	 * @param ids
	 *            需要删除的数据ID
	 * @return 结果
	 */
	@Override
	public int deleteHatchetOrderPaymentByIds(String ids) {
		return hatchetOrderPaymentMapper.deleteHatchetOrderPaymentByIds(Convert.toStrArray(ids));
	}

	/**
	 * 根据订单号获取信息
	 * 
	 * @return
	 */
	@Override
	public HatchetOrderPayment selectHatchetOrderPaymentByOrder(String orderNo) {
		List<HatchetOrderPayment> hatchetOrderPayments = hatchetOrderPaymentMapper
				.selectHatchetOrderPaymentByOrder(orderNo);
		if (hatchetOrderPayments != null && hatchetOrderPayments.size() > 0) {
			return hatchetOrderPayments.get(0);
		} else {
			return null;
		}
	}

	/**
	 * 根据交易类型获取交易记录
	 */
	@Override
	public List<HatchetOrderPayment> selectOrderPaymentByTrade(HatchetOrderPayment hatchetOrderPayment) {
		return hatchetOrderPaymentMapper.selectOrderPaymentByTrade(hatchetOrderPayment);
	}

	/**
	 * 代理商查询订单
	 * 
	 * @param hatchetOrderPayment
	 *            里面包含有商户的id集合
	 * @return
	 */
	public List<HatchetOrderPayment> selectOrderPaymentForDLS(HatchetOrderPayment hatchetOrderPayment) {

		return hatchetOrderPaymentMapper.selectOrderPaymentForDLS(hatchetOrderPayment);
	}

	/**
	 * 代还订单查询
	 * 
	 * @param hatchetOrderPayment
	 * @return
	 */
	public List<HatchetOrderPayment> selectOrderPaymentReplaceForDLS(HatchetOrderPayment hatchetOrderPayment) {
		return hatchetOrderPaymentMapper.selectOrderPaymentReplaceForDLS(hatchetOrderPayment);
	}

	/**
	 * 查询订单总金额
	 * 
	 * @param hatchetOrderPayment
	 * @return
	 */
	public BigDecimal selectSumMoney(HatchetOrderPayment hatchetOrderPayment) {
		BigDecimal selectSumMoney = hatchetOrderPaymentMapper.selectSumMoney(hatchetOrderPayment);
		if (StringUtils.isNull(selectSumMoney)) {
			return new BigDecimal("0.0");
		} else {
			return selectSumMoney;
		}
	}


	/**
	 * 查询订单数量
	 */
	public Long selectOrderPaymentCount(HatchetOrderPayment orderPayment) {
		Long count = hatchetOrderPaymentMapper.selectOrderPaymentCount(orderPayment);
		if (StringUtils.isNull(count)) {
			return 0l;
		} else {
			return count;
		}
	}

	@Override
	public List<HatchetOrderPayment> selectOrderPaymentZX(HatchetOrderPayment hatchetOrderPayment) {
		return hatchetOrderPaymentMapper.selectOrderPaymentZX(hatchetOrderPayment);
	}

	@Override
	public BigDecimal selectZXSumMoney(HatchetOrderPayment hatchetOrderPayment) {
		BigDecimal selectSumMoney = hatchetOrderPaymentMapper.selectZXSumMoney(hatchetOrderPayment);
		if (StringUtils.isNull(selectSumMoney)) {
			return new BigDecimal("0.0");
		} else {
			return selectSumMoney;
		}
	}

	@Override
	public BigDecimal selectSumMoneyForPlan(HatchetOrderPayment hatchetOrderPayment) {
		BigDecimal selectSumMoney = hatchetOrderPaymentMapper.selectSumMoneyForPlan(hatchetOrderPayment);
		if (StringUtils.isNull(selectSumMoney)) {
			return new BigDecimal("0.0");
		} else {
			return selectSumMoney;
		}
	}

	/**
	 * 按天分组查询订单金额和数量
	 * @param orderPayment
	 * @return
	 */
	public List<HatchetOrderPayment> selectHatchetOrderPaymentMoneyByDay(HatchetOrderPayment orderPayment) {
		return  hatchetOrderPaymentMapper.selectHatchetOrderPaymentMoneyByDay(orderPayment);
		
	}

	@Override
	public List<HatchetOrderPayment> selectOrderPaymentForKefu(HatchetOrderPayment hatchetOrderPayment) {
		// TODO Auto-generated method stub
		return hatchetOrderPaymentMapper.selectOrderPaymentForKefu(hatchetOrderPayment);
	}

	@Override
	public BigDecimal selectSumMoneyForKefu(HatchetOrderPayment hatchetOrderPayment) {
		// TODO Auto-generated method stub
		return hatchetOrderPaymentMapper.selectSumMoneyForKefu(hatchetOrderPayment);
	}


}
